﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System.Windows.Controls;
using Microsoft.Phone.Tasks;
using System;
using GalaSoft.MvvmLight.Messaging;
using System.Windows.Navigation;
using System.Windows.Input;
using System.Windows;
namespace CDFWPUG.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class pageAboutViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the pageAboutViewModel class.
        /// </summary>
        public pageAboutViewModel()
        {
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real": Connect to service, etc...
            ////}


            AboutSelectCommand = new RelayCommand<SelectionChangedEventArgs>(HandleAboutSelectCommand);
            PrivacyInfoCommand = new RelayCommand<RoutedEventArgs>(HandlePrivacyInfo);
        }


        public RelayCommand<SelectionChangedEventArgs> AboutSelectCommand { get; private set; }
        private void HandleAboutSelectCommand(SelectionChangedEventArgs args)
        {
            if (args.AddedItems.Count > 0)
            {
                ListBoxItem item = (ListBoxItem)args.AddedItems[0];

                switch (item.Name)
                {
                    case "itemContact":
                        ContactMe();
                        break;

                    case "itemReview":
                        RateTheApplication();
                        break;

                    case "itemApps":
                        ViewOtherApps();
                        break;
                }
            }
        }

        public RelayCommand<RoutedEventArgs> PrivacyInfoCommand { get; private set; }
        private void HandlePrivacyInfo(RoutedEventArgs e)
        {
            string url = "http://www.microsoft.com/windowsphone/en-us/privacy.aspx#location_services";
            ShowWebsite(url);
        }



        public static void ContactMe()
        {
            try
            {
                EmailComposeTask emailComposeTask = new EmailComposeTask();
                emailComposeTask.To = "support@bugail.com";
                emailComposeTask.Subject = "Cardiff WPUG v2.0";
                emailComposeTask.Show();
            }
            catch (Exception ex)
            {
                
            }
        }

        public static void RateTheApplication()
        {
            MarketplaceReviewTask review = new MarketplaceReviewTask();

            review.Show();
        }

        public static void ViewOtherApps()
        {
            MarketplaceSearchTask search = new MarketplaceSearchTask();
            search.ContentType = MarketplaceContentType.Applications;
            search.SearchTerms = "Bugail";
            search.Show();
        }

        public static void ViewAppDetails()
        {
            MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();
            marketplaceDetailTask.Show();
        }

        public static void ShowWebsite(String url)
        {
            WebBrowserTask task = new WebBrowserTask
            {
                URL=url
            };

            task.Show();
        }



        #region Messages
        protected void SendNavigationRequestMessage(Uri uri)
        {
            Messenger.Default.Send<Uri>(uri, "NavigationRequest");
        }

        protected void SendMessageBoxRequest(String message)
        {
            Messenger.Default.Send<String>(message, "MessageBoxRequest");
        }
        #endregion
    }
}